package com.aco.party.web.command.system;

import com.aco.party.model.po.Product;
import com.aco.party.util.WebModelUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by flying on 3/10/2016 0010.
 */
@Data
public class EditProductCommand extends Product {
    private List<String> platformList = new ArrayList<>();

    public void toCommand(Product po) {
        BeanUtils.copyProperties(po, this);
        if(StringUtils.isNotEmpty(po.getPlatform())){
            platformList.addAll(new ArrayList<>(Arrays.asList(po.getPlatform().split(WebModelUtil.SEPARATOR))));
        }
    }

    public void toPo(Product po) {
        BeanUtils.copyProperties(this, po);
        if(platformList != null && platformList.size() > 0){
            po.setPlatform(StringUtils.join(platformList, WebModelUtil.SEPARATOR));
        }
    }
}
